<?php


use Phinx\Seed\AbstractSeed;
use Faker\Factory as FakerFactory;
use App\Library\Utils\Arr;

class RefundSeeder extends AbstractSeed
{

    public function getDependencies(): array
    {
        return [
            'UserSeeder',
            'OrderSeeder',
        ];
    }

    /**
     * Run Method.
     *
     * Write your database seeder using this method.
     *
     * More information on writing seeders is available here:
     * https://book.cakephp.org/phinx/0/en/seeding.html
     */
    public function run()
    {
        $faker = FakerFactory::create('zh_CN');

        $users = $this->fetchAll('SELECT * FROM kg_user');
        $orders = $this->fetchAll('SELECT * FROM kg_order');

        $rows = [];
        for ($i = 0; $i < 15; $i++) {
            $user = Arr::rand($users);
            $order = Arr::rand($orders);

            $rows[] = [
                'owner_id' => $user['id'],
                'order_id' => $order['id'],
                'trade_id' => rand(100, 500),
                'sn' => $order['sn'],
                'subject' => $order['subject'],
                'amount' => $order['amount'],
                'status' => Arr::rand([2, 4, 5]),
                'apply_note' => $faker->text(15),
                'review_note' => $faker->text(15),
                'create_time' => $faker->unixTime,
                'update_time' => $faker->unixTime,
            ];
        }
        $this->table('kg_refund')->insert($rows)->saveData();
    }
}
